package org.innovasix.educational.javap.domain.constantpool;

import org.innovasix.educational.javap.domain.datatypes.cp_info;
import org.innovasix.educational.javap.domain.datatypes.u1;
import org.innovasix.educational.javap.domain.datatypes.u2;
import org.innovasix.educational.javap.domain.parser.ByteQueue;

/**
 * <p>
 * <b><i>From the JVM specification:</i></b><br/>
 * The CONSTANT_Fieldref_info structure is used to represent a field.
 * </p>
 * 
 * @see <a
 *      href="http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.4.1">4.4.1.
 *      The CONSTANT_Class_info Structure</a>
 * 
 * @author sven.mentl@gmail.com
 * 
 */
public class CONSTANT_Fieldref_info extends cp_info {

	public CONSTANT_Fieldref_info(ByteQueue byteQueue) {
		class_index = byteQueue.pollTwoBytes("CONSTANT_Fieldref_info structure");
		name_and_type_index =  byteQueue.pollTwoBytes("CONSTANT_Fieldref_info structure");
	}

	/**
	 * <p>
	 * <b><i>From the JVM specification:</i></b><br/>
	 * The tag item has the value CONSTANT_Fieldref(9).
	 * </p>
	 */
	final u1 tag = new u1(ConstantPoolTags.CONSTANT_Fieldref.decimalValue());

	/**
	 * <p>
	 * <b><i>From the JVM specification:</i></b><br/>
	 * The value of the class_index item must be a valid index into the
	 * constant_pool table. The constant_pool entry at that index must be a
	 * CONSTANT_Class_info structure representing a class or interface type that
	 * has this field as a member.
	 * </p>
	 */
	u2 class_index;

	/**
	 * <p>
	 * <b><i>From the JVM specification:</i></b><br/>
	 * The value of the name_and_type_index item must be a valid index into the
	 * constant_pool table. The constant_pool entry at that index must be a
	 * CONSTANT_NameAndType_info structure. This constant_pool entry indicates the name and descriptor of the field.
	 * The descriptor is a field descriptor (which is a sequence of characters e.g.: Ljava/lang/Object)
	 * </p>
	 */
	u2 name_and_type_index;
}
